//
//  BaseTableViewController.swift
//  SwiftWB
//
//  Created by 吴志勇 on 2019/6/14.
//  Copyright © 2019 wzy. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {

    //检查是否登录
    var isLogin = true
    
    var visitorView: VisitorView?
    
    
    
    override func loadView() {
        //判断t用户是否登录，如果没有登录就显示访客界面，如果已经登录就显示tableView
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    //MARK: -未登录页面
    private func setupVisitorView(){
        //1.创建访客视图
        visitorView = VisitorView.visitorView()
        view = visitorView
        visitorView?.delegate = self
        
        visitorView?.loginButton.addTarget(self, action: #selector(loginBtnClick(btn:)), for: .touchUpInside)
        visitorView?.registerButton.addTarget(self, action: #selector(registerBtnClick(btn:)), for: .touchUpInside)
        
        //导航条按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(loginBtnClick(btn:)))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(registerBtnClick(btn:)))
        
        
    }
    
    @objc private func loginBtnClick(btn: UIButton){
    
    }
    
    @objc private func registerBtnClick(btn: UIButton){
        
    }

}

extension BaseTableViewController: VisitorViewDelegate{
    func visitorViewDidClickLoginBtn(visiot:VisitorView){
        
    }
    
    func visitorViewDidClickRegisterBtn(visiot:VisitorView){
        
    }
}
